﻿using Furion;
using Furion.DependencyInjection;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using UAParser;

namespace PrivateTracker.NET.Application.Services
{
    public class ClientService : IClientService, ITransient
    {
        public async Task<bool> IsAllowClinet()
        {
            bool b = false;
            string[] patteron = { "^uTorrent/", "^Azureus ", "^BitComet/", "^qBittorrent/", "^Transmission/", "^BiglyBT" };
            var client = Parser.GetDefault().Parse(App.GetService<IHttpContextAccessor>().HttpContext.Request.Headers["User-Agent"]).String;
            foreach (var item in patteron)
            {
                if (Regex.IsMatch(client, item))
                {
                    b = true;
                    break;
                }
            }
            return await Task.FromResult(b);
        }
    }
}
